package demo1;

import java.math.BigInteger;
import java.util.*;

/**
 * @Author liangzai
 * @Description:
 */
public class Test {
    public static void main(String[] args) {

    }

    //砝码称重
    public static void main2(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        Set<Integer> set = new HashSet<>();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = scan.nextInt();
        }
        set.add(0);
        for (int i = 0; i < n; i++) {
            List<Integer> list = new ArrayList<>(set);
            for(int k:list){
                set.add(k+array[i]);
                set.add(Math.abs(k-array[i]));
            }
        }
        System.out.println(set.size()-1);
    }

    public static void main1(String[] args) {
        int i = 0,last_i=0;
        int[] array = {4,2,6,3,9};
        findWinningPlayer(array,2);
    }

    //找到连赢k长的第一位玩家
    public static int findWinningPlayer(int[] skills, int k) {
        Queue<Integer> queue = new LinkedList<>();
        HashMap<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < skills.length; i++) {
            queue.offer(skills[i]);
            map.put(skills[i],i);
        }
        if(k>=skills.length-1){
            Arrays.sort(skills);
            return map.get(skills[skills.length-1]);
        }
        int count = 0;
        int ret = 0;
        while (true) {
            int val = queue.poll();
            for (int i = 0; i < k && count!=k; i++) {
                if (val > queue.peek()) {
                    queue.offer(queue.poll());
                    count++;
                }else {
                    if(k==1){
                        return map.get(queue.peek());
                    }
                    queue.offer(val);
                    count = 1;
                    break;
                }
            }
            if (count == k) {
                ret = val;
                break;
            }
        }
        return map.get(ret);
    }
}
